import * as actions from '../actionTypes/'

const user = (
    state = {
        userInfo: {},
        loginModal: {
            isOpen: false,
            isLogin: true,
        },
    },
    action
) => {
    switch (action.type) {
        case 'AUTH_USER_SUCCESS':
            return {
                ...state,
                authInfo: action.data,
            }
        case actions.TOGGLE_LOGIN_MODAL:
            return {
                ...state,
                loginModal: action.payload
                    ? action.payload
                    : {
                          isOpen: false,
                          isLogin: true,
                      },
            }
        case actions.SET_USER_INFO:
            return {
                ...state,
                userInfo: action.payload ? action.payload : {},
            }
        case actions.LOGOUT_USER_SUCCESS:
            return {
                ...state,
                userInfo: {},
            }
        case actions.LOGIN_USER_SUCCESS:
            return {
                ...state,
                loginModal: {
                    isOpen: false,
                    isLogin: true,
                },
                userInfo: action.payload ? action.payload : {},
            }

        default:
            return state
    }
}

export default user



// WEBPACK FOOTER //
// ./src/reducers/user.js